package com.mdd.front.controller.order;


import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import com.mdd.front.service.order.IOrderAcceptService;
import com.mdd.front.validate.common.IdValidate;
import com.mdd.front.validate.common.PageValidate;
import com.mdd.front.validate.order.OrderAcceptCreateValidate;
import com.mdd.front.validate.order.OrderAcceptSearchValidate;
import com.mdd.front.validate.order.OrderAcceptUpdateValidate;
import com.mdd.front.vo.order.OrderAcceptDetailVo;
import com.mdd.front.vo.order.OrderAcceptListedVo;
import com.mdd.front.vo.order.completedList.CompletedListVo;
import com.mdd.front.vo.order.reservedList.OrderReservedListVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/orderAccept")
@Api(tags = "接单管理")
public class OrderAcceptController {

    @Resource
    IOrderAcceptService iOrderAcceptService;

    @GetMapping("/list")
    @ApiOperation(value="接单列表")
    public AjaxResult<PageResult<OrderAcceptListedVo>> list(@Validated PageValidate pageValidate,
                                                            @Validated OrderAcceptSearchValidate searchValidate) {
        PageResult<OrderAcceptListedVo> list = iOrderAcceptService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/reservedList")
    @ApiOperation(value="已预约列表(服务中列表)")
    public AjaxResult<PageResult<OrderReservedListVo>> reservedList(@Validated PageValidate pageValidate,
                                                                    @Validated OrderAcceptSearchValidate searchValidate) {
        PageResult<OrderReservedListVo> list = iOrderAcceptService.reservedList(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }


    @GetMapping("/completedList")
    @ApiOperation(value="完工/关闭列表(师傅端确认后)")
    public AjaxResult<PageResult<CompletedListVo>> completedList(@Validated PageValidate pageValidate,
                                                                 @Validated OrderAcceptSearchValidate searchValidate) {
        PageResult<CompletedListVo> list = iOrderAcceptService.completedList(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }
    @GetMapping("/detail")
    @ApiOperation(value="接单详情")
    public AjaxResult<OrderAcceptDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        OrderAcceptDetailVo detail = iOrderAcceptService.detail(id);
        return AjaxResult.success(detail);
    }

    @PostMapping("/add")
    @ApiOperation(value="接单新增")
    public AjaxResult<Object> add(@Validated @RequestBody OrderAcceptCreateValidate createValidate) {
        iOrderAcceptService.add(createValidate);
        return AjaxResult.success();
    }
    @PostMapping("/appointment")
    @ApiOperation(value="立刻预约/确定预约")
    public AjaxResult<Object> appointment(@Validated @RequestBody OrderAcceptCreateValidate createValidate) {
        iOrderAcceptService.appointment(createValidate);
        return AjaxResult.success();
    }

    @PostMapping("/receivePayment")
    @ApiOperation(value="确认收款(完工/关闭)")
    public AjaxResult<Object> receivePayment(@Validated @RequestBody OrderAcceptCreateValidate createValidate) {
        iOrderAcceptService.receivePayment(createValidate);
        return AjaxResult.success();
    }

    @PostMapping("/edit")
    @ApiOperation(value="接单编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody OrderAcceptUpdateValidate updateValidate) {
        iOrderAcceptService.edit(updateValidate);
        return AjaxResult.success();
    }

    @PostMapping("/del")
    @ApiOperation(value="接单删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iOrderAcceptService.del(idValidate.getId());
        return AjaxResult.success();
    }

}
